import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
Page({
  data: {
    show: false,
    option1: [
      { text: '全部校区', value: 2 },
      { text: '社湾校区', value: 0 },
      { text: '官塘校区', value: 1 },
    ],
    option2: [
      { text: '全部物品', value: 'a' },
      { text: '身份证', value: 'b' },
      { text: '学生卡', value: 'c' },
      { text: '银行卡', value: 'd' },
      { text: '电子产品', value: 'e' },
      { text: '雨伞衣物', value: 'f' },
      { text: '钥匙书本', value: 'g' },
      { text: '其他', value: 'h' },
    ],
    value1: 2,
    value2: 'a',
    // 失物招领数据
    swzl: [],
    // 点击放大物品的数据
    swzl1: {},
    // 从数据库获取到的数据暂存
    qaq: []
  },
  onShow(){
    this.getData()
    this.setData({
      value1: 2,
      value2: 'a',
    })
  },
  onLoad() {
    // wx.request({
    //   url: 'http://localhost:3000/',
    //   success: res => {
    //     console.log(res.data.list)
    //     this.setData({
    //       swzl: res.data.list
    //     })
    //   }
    // })
  },
  getData() {
    // 调用云函数获取数据库的数据
    wx.cloud.callFunction({
      name: 'getSwzl',
      success: res => {
        console.log(res)
        this.setData({
          swzl: res.result.data,
          qaq: res.result.data
        })
      }
    })
  },
  a(value1) {
    // 临时变量
    let lsbl = []
    console.log(value1.detail)
    if (value1.detail == 0) {
      console.log(this.data.swzl)
      for (let i = 0; i < this.data.qaq.length; i++) {
        if (this.data.qaq[i].xq == '社湾校区') {
          lsbl.push(this.data.qaq[i])
        }
      }
      this.setData({
        swzl: lsbl
      })
    } else if (value1.detail == 1) {
      for (let i = 0; i < this.data.qaq.length; i++) {
        if (this.data.qaq[i].xq == '官塘校区') {
          lsbl.push(this.data.qaq[i])
        }
      }
      this.setData({
        swzl: lsbl
      })
    } else {
      this.setData({
        swzl: this.data.qaq
      })
    }
  },
  b(value2) {
    let lsbl = []
    console.log(value2.detail)
    if (value2.detail == 'b') {
      for (let i = 0; i < this.data.qaq.length; i++) {
        if (this.data.qaq[i].typea == '身份证') {
          lsbl.push(this.data.qaq[i])
        }
      }
      this.setData({
        swzl: lsbl
      })
    } else if (value2.detail == 'c') {
      for (let i = 0; i < this.data.qaq.length; i++) {
        if (this.data.qaq[i].typea == '学生卡') {
          lsbl.push(this.data.qaq[i])
        }
      }
      this.setData({
        swzl: lsbl
      })
    } else if (value2.detail == 'd') {
      for (let i = 0; i < this.data.qaq.length; i++) {
        if (this.data.qaq[i].typea == '银行卡') {
          lsbl.push(this.data.qaq[i])
        }
      }
      this.setData({
        swzl: lsbl
      })
    } else if (value2.detail == 'e') {
      for (let i = 0; i < this.data.qaq.length; i++) {
        if (this.data.qaq[i].typea == '电子产品') {
          lsbl.push(this.data.qaq[i])
        }
      }
      this.setData({
        swzl: lsbl
      })
    } else if (value2.detail == 'f') {
      for (let i = 0; i < this.data.qaq.length; i++) {
        if (this.data.qaq[i].typea == '雨伞衣物') {
          lsbl.push(this.data.qaq[i])
        }
      }
      this.setData({
        swzl: lsbl
      })
    } else if (value2.detail == 'g') {
      for (let i = 0; i < this.data.qaq.length; i++) {
        if (this.data.qaq[i].typea == '钥匙书本') {
          lsbl.push(this.data.qaq[i])
        }
      }
      this.setData({
        swzl: lsbl
      })
    } else if (value2.detail == 'h') {
      for (let i = 0; i < this.data.qaq.length; i++) {
        if (this.data.qaq[i].typea == '其他') {
          lsbl.push(this.data.qaq[i])
        }
      }
      this.setData({
        swzl: lsbl
      })
    } else if (value2.detail == 'a') {

      this.setData({
        swzl: this.data.qaq
      })
    }

  },
  dialog(e) {
    this.setData({ show: true });
    for (let i = 0; i < this.data.swzl.length; i++) {
      if (this.data.swzl[i].id == e.currentTarget.dataset.id) {
        this.setData({
          swzl1: this.data.swzl[i]
        })
        console.log(this.data.swzl1)
      }
    }
  },
  onClose() {
    this.setData({ show: false });
  },
  // 跳转发布失物招领页面
  toaddswzl() {
    let openid = wx.getStorageSync('openid')
    if (openid != '') {
      wx.navigateTo({
        url: '../../pages/addswzl/addswzl',
      })
    } else {
      wx.showToast({
        title: '请登录',
        icon: 'error'
      })
    }

  }
});